package com.qys.training.server.controller;

import com.qys.training.base.dto.BaseResult;
import com.qys.training.biz.sysconfig.entity.SysConfig;
import com.qys.training.biz.sysconfig.service.SysConfigService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/config")
public class SysConfigController {

    public static final Logger logger = LoggerFactory.getLogger(SysConfigController.class);

    @Autowired
    private SysConfigService sysConfigService;


    /**
     * 增加
     * @param config
     * @return
     */
    @PostMapping()
    public @ResponseBody
    BaseResult add(@RequestBody SysConfig config) {
        return BaseResult.success(sysConfigService.create(config));
    }


    /**
     * 取值
     * @param key
     * @return
     */
    @GetMapping("{key}")
    public @ResponseBody
    BaseResult get(@PathVariable String key)  {
        return BaseResult.success(sysConfigService.getByKey(key));
    }


    /**
     * 删值
     * @param key
     * @return
     */
    @DeleteMapping("/{key}")
    public @ResponseBody
    BaseResult delete(@PathVariable String key)  {
        sysConfigService.delete(key);
        return BaseResult.success();
    }

}
